package com.springbootcrud.user.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.springbootcrud.user.controller.CrudController;
import com.springbootcrud.user.dao.CrudDao;
import com.springbootcrud.user.entity.Crud;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Sun on 2020/4/10.
 */
@Service
public class CrudServiceImpl implements CrudService {

    @Autowired
    CrudDao  crudDao;

    @Override
    public List<CrudController> getAll(Map map) {
        List<CrudController> list =  crudDao.getAll(map);
        return list;
    }

    @Override
    public void delete(Integer id) {
        crudDao.delete(id);
    }

    @Override
    public void save(Crud crud) {
        crud.setCreatetime(new Date());
        crudDao.sava(crud);
    }

    @Override
    public Crud getById(Integer id) {
        return crudDao.getById(id);
    }

    @Override
    public void saveCrud(Crud crud) {
        crudDao.saveCrud(crud);
    }

    @Override
    public List<Crud> queryUserInfo() {
        return crudDao.queryUserInfo();
    }

    @Override
    public List<Crud> findAllUserByPageF(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Crud> lists = crudDao.queryUserInfo();
        return lists;
    }

    @Override
    public PageInfo<Crud> findAllUserByPageS(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Crud> lists = crudDao.queryUserInfo();
        PageInfo<Crud> pageInfo = new PageInfo<Crud>(lists);
        return pageInfo;
    }





}
